package com.suixinsanren.design.state.demo.demo01;

public class WinterState implements State {

    private GumballMachine gumballMachine;

    public WinterState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    @Override
    public void insertQuarter() {
        System.out.println("请稍等，我们正在为您准备糖果");
    }

    @Override
    public void ejectQuarter() {
        System.out.println("不好意思您已经转动曲柄，无法退钱");
    }

    @Override
    public void turnCrank() {
        System.out.println("转两圈不会给你带来另一个糖果");
    }

    @Override
    public void dispense() {
        System.out.println("你是幸运星");
        gumballMachine.releaseBall();
        if (gumballMachine.getCount() == 0) {
            gumballMachine.setState(gumballMachine.getSoldOutState());
        } else {
            gumballMachine.releaseBall();
            if (gumballMachine.getCount() > 0) {
                gumballMachine.setState(gumballMachine.getNoQuarterState());
            } else {
                System.out.println("哎呀，糖果买完了");
                gumballMachine.setState(gumballMachine.getSoldOutState());
            }
        }
    }
}
